import { Injectable } from '@angular/core';

import MockData from '../assets/MockData.json';
import { ChartType } from './routes/ChartType';

@Injectable({
  providedIn: 'root'
})
export class DataSourceService {
  constructor() {}

  getChartLength(chartType: ChartType): number {
    let length: number = 0;
    switch (chartType) {
      case ChartType.Xbar_Rbar:
        length = MockData.XbarR.length;
        break;
      case ChartType.Xbar_Sbar:
        length = MockData.XbarS.length;
        break;
      case ChartType.Xbar_Median:
        length = MockData.Median.length;
        break;
      case ChartType.Xbar_Mr:
        length = MockData.XbarMr.length;
        break;
      case ChartType.P:
        length = MockData.PChart.length;
        break;
      case ChartType.NP:
        length = MockData.NPChart.length;
        break;
      case ChartType.U:
        length = MockData.UChart.length;
        break;
      case ChartType.C:
        length = MockData.CChart.length;
        break;
      default:
        console.error('Unsupported chart type!');
        break;
    }

    return length;
  }

  getSampleID(chartType: ChartType, index: number): number {
    let sampleID: number = 0;
    switch (chartType) {
      case ChartType.Xbar_Rbar:
        sampleID = MockData.XbarR[index].SampleID;
        break;
      case ChartType.Xbar_Sbar:
        sampleID = MockData.XbarS[index].SampleID;
        break;
      case ChartType.Xbar_Median:
        sampleID = MockData.Median[index].SampleID;
        break;
      case ChartType.Xbar_Mr:
        sampleID = MockData.XbarMr[index].SampleID;
        break;
      case ChartType.P:
        sampleID = MockData.PChart[index].SampleID;
        break;
      case ChartType.NP:
        sampleID = MockData.NPChart[index].SampleID;
        break;
      case ChartType.U:
        sampleID = MockData.UChart[index].SampleID;
        break;
      case ChartType.C:
        sampleID = MockData.CChart[index].SampleID;
        break;
      default:
        console.error('Unsupported chart type!');
        break;
    }

    return sampleID;
  }

  getSampleResultData(chartType: ChartType, index: number): any {
    let result: any = 0;
    switch (chartType) {
      case ChartType.Xbar_Rbar:
        result = MockData.XbarR;
        break;
      case ChartType.Xbar_Sbar:
        result = MockData.XbarS;
        break;
      case ChartType.Xbar_Median:
        result = MockData.Median;
        break;
      case ChartType.Xbar_Mr:
        result = MockData.XbarMr;
        break;
      case ChartType.P:
        result = MockData.PChart[index].Result;
        break;
      case ChartType.NP:
        result = MockData.NPChart[index].Result;
        break;
      case ChartType.U:
        result = MockData.UChart[index].Result;
        break;
      case ChartType.C:
        result = MockData.CChart[index].Result;
        break;
      default:
        console.error('Unsupported chart type!');
        break;
    }

    return result;
  }

  getSampleSize(chartType: ChartType, index: number): number {
    let sampleSize: number = 0;
    switch (chartType) {
      case ChartType.Xbar_Rbar:
        break;
      case ChartType.Xbar_Sbar:
        break;
      case ChartType.Xbar_Median:
        break;
      case ChartType.Xbar_Mr:
        break;
      case ChartType.P:
        sampleSize = MockData.PChart[index].SampleSize;
        break;
      case ChartType.NP:
        sampleSize = MockData.NPChart[index].SampleSize;
        break;
      case ChartType.U:
        sampleSize = MockData.UChart[index].SampleSize;
        break;
      case ChartType.C:
        sampleSize = MockData.CChart[index].SampleSize;
        break;
      default:
        console.error('Unsupported chart type!');
        break;
    }

    return sampleSize;
  }

  getRandomMin(): number {
    return MockData.randomMin;
  }

  getRandomMax(): number {
    return MockData.randomMax;
  }
}
